package gudaziEx.entity;

import com.alibaba.fastjson.JSONObject;
import commons.entity.Constant;
import commons.entity.NativeCp;
import commons.util.GameUtil;
import commons.util.PropertiesUtil;

import java.awt.*;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.List;

public class MovePoints {
    public static MovePoints mps;
    public static MovePoints getInstance(){
        System.setProperty("sun.jnu.encoding", "UTF-8");

            String name = PropertiesUtil.getValueFromSDFile("SDName");
            String filepath = NativeCp.getUserDir() + "/config/"+ Constant.MOVE_POINTS +"/"+ name;
//            mps = JSONObject.parseObject(GameUtil.getJsonString(filepath), MovePoints.class);

// 如果jsonString是文件读取的结果，确保文件是UTF-8编码，或者使用如下方式读取：
        BufferedReader reader = null;
        StringBuilder sb = new StringBuilder();
        try {
            reader = new BufferedReader(new InputStreamReader(new FileInputStream(filepath), StandardCharsets.UTF_8));
            String line;
            while ((line = reader.readLine()) != null) {
                sb.append(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        String jsonStringFromFile = sb.toString();
        mps = JSONObject.parseObject(jsonStringFromFile, MovePoints.class);


        return mps;
    }
    private String name;
    private List<Point> movePoints;

    public List<Point> getMovePoints() {
        return movePoints;
    }

    public void setMovePoints(List<Point> movePoints) {
        this.movePoints = movePoints;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
